package com.esunny.resourcevisualization.controller;

import com.esunny.resourcevisualization.domain.response.ReturnStructure;
import com.esunny.resourcevisualization.service.LoginService;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @version 1.0.0.0
 * @ClassName LoginController
 * @Description 登录模块接口
 * @Author baochencong
 * @Date 2020/10/9 19:48
 */
@Controller
public class LoginController {

    @Resource
    private LoginService loginService;

    /**
     * 登录
     *
     * @param loginMap 登录信息map
     * @return 登录结果信息
     */
    @ResponseBody
    @PostMapping("/login")
    public ReturnStructure login(@NotNull @RequestBody Map<String, String> loginMap) {
        String username = loginMap.get("username");
        String password = loginMap.get("password");
        if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
            return ReturnStructure.NOT_FOUND("用户名或密码不能为空", null);
        }
        return loginService.login(username,password);
    }
}
